package com.itheima.demo02;

import java.util.TreeSet;

public class MainClass02 {
    public static void main(String[] args) {
        TreeSet<Teacher> teachers = new TreeSet<>((o1,o2) -> {
            int result = o1.getAge() - o2.getAge();
            return result == 0 ? o1.getName().compareTo(o2.getName()) : result;
        });

        Teacher teacher1 = new Teacher("zhangsan", 23);
        Teacher teacher2 = new Teacher("zhanghua", 23);
        Teacher teacher3 = new Teacher("zhangli", 23);
        Teacher teacher4 = new Teacher("zhangmin", 23);

        teachers.add(teacher1);
        teachers.add(teacher2);
        teachers.add(teacher3);
        teachers.add(teacher4);

        for (Teacher teacher : teachers) {
            System.out.println(teacher);
        }
    }
}
